import { StyleSheet, Text, View, Button } from 'react-native'
import React from 'react'
import { connect } from 'react-redux'
import { testAction, testListAction } from '../redux/actionCreator/test'
import store from '../redux/store'
import { useEffect } from 'react'

const Test = ({ num, list }) => {
  useEffect(()=>{
    console.log('list', list)
  }, [])
  const add = () => {
    store.dispatch(testAction())
    console.log('add')
  }
  const setList = () => {
    console.log('setList')
    store.dispatch(testListAction())
  }
  return (
    <View>
      <Text>{num}</Text>
      <Button title='add' onPress={setList}></Button>
      {
        list?.length>0 && list.map(item => <Text key={item.num}>{item.num}</Text>)
      }
    </View>
  )
}

export default connect((state)=>{
  return {
    num: state.testReducer.obj.num,
    list: state.testReducer.list
  }
})(Test)

const styles = StyleSheet.create({})